package com.zwan.oam_rtc.utils.messages;

import java.nio.ByteBuffer;
import java.util.Arrays;

public class WinnttcpMsg extends AbstractStruct {

    private MessageHead head = new MessageHead();
    private byte[] body = new byte[Const.TCP_CHECK_BODYLEN];

    public WinnttcpMsg() {
        Arrays.fill(body, (byte) 0);
    }

    public int getLength() {
        return head.getLength() + body.length;
    }

    public void readFromBuffer(ByteBuffer bf) {
        head.readFromBuffer(bf);
        if (body.length != head.getBodyLen())
            body = new byte[head.getBodyLen()];
        Arrays.fill(body, (byte) 0);
        bf.get(body);
    }

    public void writeToBuffer(ByteBuffer bf) {
        head.setBodyLen(body.length);
        head.writeToBuffer(bf);
        bf.put(body);
    }

    public byte[] getBody() {
        return body;
    }

    public MessageHead getHead() {
        return head;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public void setHead(MessageHead head) {
        this.head = head;
    }

}
